﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups.achievement {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.controls.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.vo.*;
    import net.wooga.pets.views.popups.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class AchievementShareRewardPopupMediator extends AbstractPopupMediator {

        private var _isRewardCollected:Boolean;// = false

        override public function onRegister():void{
            super.onRegister();
            addContextListener(EventConstants.ACHIEVEMENT_REWARD_COLLECTED, this.achievementRewardCollected);
            var _local1:RewardVO = RewardVO(this.view.data);
            RepriseUtils.addComponent(this.view, ("rewardGraphic " + _local1.achievementVO.id));
            var _local2:UIComponent = RepriseUtils.addComponent(this.view, "redBand");
            RepriseUtils.addLabel(_local2, "redBandLabel showcardGothicFont", this.getBandText(_local1));
            RepriseUtils.addComponent(this.view, "rewardAnimationOneShot");
            RepriseUtils.addComponent(this.view, "rewardLoopAnimation");
            var _local3:LabelButton = RepriseUtils.addLabelButton(this.view, "rectButton", language.getTextByKey("global_button_share"), this.shareButton_click);
            _local3.setData(_local1);
            var _local4:UIComponent = RepriseUtils.addComponent(this.view, "rewardDisplay");
            RepriseUtils.addComponent(_local4, (_local1.rewardType + "Icon"));
            addLabel("numberOfRewardsLabel", "global_text", {text:("x" + _local1.numberOfRewardsYouGet)}, _local4);
            RepriseUtils.addComponent(_local4, "xpIcon");
            addLabel("numberOfXPLabel", "global_text", {text:("x" + _local1.xpYouGet)}, _local4);
            RepriseUtils.addComponent(_local4, ("medal " + _local1.medal));
            addLabel("plusLabel", "global_text", {text:"+"}, _local4);
            addLabel("yourRewardLabel", "global_yourreward");
            addLabel("hintLabel", "achievement_getreward_hint");
            addLabel("title showcardGothicFontOutline", "achievement_getreward_title");
            dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, GameConstants.SOUND_HARVEST));
        }
        private function shareButton_click(_arg1:MouseEvent):void{
            var _local4:Object;
            var _local2:LabelButton = LabelButton(_arg1.target);
            var _local3:RewardVO = _local2.data();
            if (this._isRewardCollected){
                _local4 = {type:GameConstants.POST_ACHIEVEMENT, vo:_local3};
                dispatch(new InfoEvent(EventConstants.POST_ON_WALL, null, _local4));
            };
            close();
        }
        private function achievementRewardCollected(_arg1:Event):void{
            this._isRewardCollected = true;
        }
        private function getBandText(_arg1:RewardVO):String{
            var _local2:String = ("achievement_reached_" + _arg1.achievementVO.id);
            return (language.getTextByKey(_local2, {amount:_arg1.pointsNeeded}));
        }
        private function get view():AchievementShareRewardPopup{
            return (AchievementShareRewardPopup(getViewComponent()));
        }

    }
}//package net.wooga.pets.views.popups.achievement 
